package pyip.lib.javalearn.aop.dynamicproxy.spring.aspectj.annotation;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import pyip.lib.javalearn.aop.dynamicproxy.Greeting;

public class Client {

    public static void main(String[] args) {
        declarationPattern();
    }

    private static void declarationPattern() {
        ApplicationContext context = new ClassPathXmlApplicationContext("pyip/lib/javalearn/aop/dynamicproxy/spring/aspectj/annotation/aop-aspectjannotation.xml");
        // 注意：转型为接口
        Greeting greeting = (Greeting) context.getBean("greetingAnnotationImpl");
        greeting.sayHello("Jack");

        // 注意：转型为目标类，而并非它的 Greeting 接口
        GreetingAnnotationImpl greetingAnnotationImpl = (GreetingAnnotationImpl) context.getBean("greetingAnnotationImpl");
        greetingAnnotationImpl.sayHello("Jack");
        greetingAnnotationImpl.goodMorning("Jack");
        greetingAnnotationImpl.goodNight("Jack");

        ((ClassPathXmlApplicationContext) context).close();
    }

}